package model.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

import util.DataSourceUtil;

import model.beans.ClientBean;
import model.dao.ClientDAO;

public class ClientDAOImp implements ClientDAO{

	@Override
	public ClientBean getClient(String username, String password) {		
		ClientBean client = null;		
		try {
			DataSource dataSource = DataSourceUtil.getDataSource();
			Connection conn = dataSource.getConnection();
			Statement statement = conn.createStatement();		
			statement = conn.createStatement();			
			statement.executeUpdate("Set Schema roumani");	
			ResultSet rs= statement.executeQuery("SELECT * FROM CLIENT WHERE NUMBER =" + username + " and PASSWORD = '"+ password +"'");
			
			while (rs.next()){
				client = new ClientBean();
				client.setNumber(rs.getInt("number"));
				client.setName(rs.getString("name"));								
			}			
			statement.close();
			conn.close();		
		} catch (Exception e){
			System.out.println("sql error!\n" + e);
		}
		
		return  client;
	}

}
